package com.qzsoft.zhjd.asphalt.modules.asphaltmatch.controller;

import java.util.Map;

import com.qzsoft.jeemis.common.validator.ValidatorUtils;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.dto.AsphaltMatchThresholdDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.entity.AsphaltMatchThresholdEntity;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.service.AsphaltMatchThresholdService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.enums.BizCode;
import com.qzsoft.zhjd.common.utils.ResultUtils;

/**
 * @ClassName AsphaltMatchThresholdController
 * @Description 上下限上下限控制器
 * @author linhuawei
 * @since 2021-09-06
 */
@RestController
@RequestMapping("/api/asphaltMatchThreshold")
public class AsphaltMatchThresholdController {

    @Autowired
    private AsphaltMatchThresholdService asphaltMatchThresholdService;

    /**
     * @Title page
     * @Description 获取上下限分页数据
     * @param params 查询条件
     * @return 上下限分页数据
     */
    @RequiresPermissions("api:asphaltMatchThreshold:list")
    @GetMapping("/page")
    public Result<IPage<AsphaltMatchThresholdEntity>> page(@RequestParam Map<String, Object> params) {
        IPage<AsphaltMatchThresholdEntity> page = asphaltMatchThresholdService.page(params);
        return ResultUtils.ok(page);
    }

    /**
     * @Title: find
     * @Description: 获取上下限信息
     * @param id 上下限主键
     * @return 上下限信息
     */
    @RequiresPermissions("api:asphaltMatchThreshold:edit")
    @GetMapping("/find/{id}")
    public Result<AsphaltMatchThresholdDto> find(@PathVariable("id") String id) {
        AsphaltMatchThresholdDto data = asphaltMatchThresholdService.getDtoById(id);
        if (null == data) {
            return ResultUtils.error(BizCode.DATA_NOT_FOUND);
        }
        return ResultUtils.ok(data);
    }

    /**
     * @Title: save
     * @Description: 添加上下限信息
     * @param entity 上下限信息
     * @return 添加结果
     */
    @RequiresPermissions("api:asphaltMatchThreshold:save")
    @PostMapping("/save")
    public Result<String> save(@RequestBody AsphaltMatchThresholdEntity entity) {
        ValidatorUtils.validateEntity(entity);
        asphaltMatchThresholdService.save(entity);
        return ResultUtils.ok();
    }

    /**
     * @Title: update
     * @Description: 修改上下限信息
     * @param entity 上下限信息
     * @return 修改结果
     */
    @PostMapping("/update")
    public Result<String> update(@RequestBody AsphaltMatchThresholdEntity entity) {
        ValidatorUtils.validateEntity(entity);
        asphaltMatchThresholdService.updateById(entity);
        return ResultUtils.ok();
    }

    /**
     * @Title: delete
     * @Description: 删除上下限信息
     * @param ids 上下限主键
     * @return 删除结果
     */
    @RequiresPermissions("api:asphaltMatchThreshold:remove")
    @PostMapping("/delete/{id}")
    public Result<String> delete(@PathVariable("id") String ids) {
        asphaltMatchThresholdService.removeById(ids);
        return ResultUtils.ok();
    }

}
